package com.bleeth.fx.component;

import cn.hutool.core.util.StrUtil;
import com.bleeth.fx.helper.SStyleHelper;
import com.bleeth.fx.helper.ThemeTypeEnum;
import com.bleeth.fx.meta.ViewRouter;
import javafx.beans.property.SimpleStringProperty;
import javafx.event.EventHandler;
import javafx.scene.control.Hyperlink;
import lombok.Builder;


/**
 * @author Sakura
 * @version 1.0
 * @date 2021-11-13 22:17
 **/
@Builder
public class MLink {

    @Builder.Default
    private String type = "primary";

    @Builder.Default
    private boolean disabled = false;

    private String href;

    private String icon;

    private String text;

    private EventHandler onAction;

    private SimpleStringProperty _type;


    public Hyperlink make() {
        Hyperlink hyperlink = new Hyperlink();
        hyperlink.setStyle("");
        if (StrUtil.isNotEmpty(type)) {
            SStyleHelper.node(hyperlink).addStyle("-fx-text-fill", ThemeTypeEnum.getMatched(type).getValue());
        }

        if (StrUtil.isNotEmpty(text)) {
            hyperlink.setText(text);
        }
        if (StrUtil.isNotEmpty(icon)) {
//            hyperlink.setGraphic(MIcon);
            hyperlink.setGraphicTextGap(10);
        }
        if (StrUtil.isNotEmpty(href)) {
            hyperlink.setOnAction(event -> {
                ViewRouter.builder().push(href);
            });
        }


        SStyleHelper.node(hyperlink)
                .addStyle("-fx-font-size", "16")
                .addStyle("-fx-border-width", "0")
                .addHoverStyle("-fx-underline", "true")
                .apply();

        hyperlink.setDisable(disabled);
        hyperlink.setOnAction(onAction);
        return hyperlink;
    }

}
